﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Nia.Globalization.Tools
{
    class Program
    {
        /// <summary>
        /// args[0]: codepage to output
        /// args[1]: [optional, default=cp.tlb] output file name
        /// </summary>
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                ShowUsage();
                return;
            }

            int icp = 0;
            if (args.Length >= 1)
                if (!int.TryParse(args[0], out icp))
                {
                    Console.WriteLine("cp must be a valid codepage number");
                    return;
                }

            string output = icp + ".tlb";
            if (args.Length >= 2)
                output = args[2];


            GenerateCP(icp, output);
        }

        private static void GenerateCP(int icp, string output)
        {
            try
            {
                var e = Encoding.GetEncoding(icp);
                using (StreamWriter sw = new StreamWriter(output, false, Encoding.Unicode))
                {
                    for (int i = 0; i < 5000; i++)
                    {
                        //TODO:
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        private static void ShowUsage()
        {
            Console.WriteLine("tblgen [cp] <output>");
            Console.WriteLine(@"sample: tblgen 936");
            Console.WriteLine(@"sample: tblgen 936 1.txt");
            Console.WriteLine(@"sample: tblgen 936 c:\1.txt");
            Console.ReadLine();
        }
    }
}
